﻿const gulp = require('gulp');
const ts = require('gulp-typescript');
const tsProj = ts.createProject('tsconfig.json');

gulp.task('tsc', () => {
    gulp.src("./src/**/*.ts")
        .pipe(ts(tsProj))
        .pipe(gulp.dest('dist/src'));
});

gulp.task("publish", () => {
    var file = [
        'package.json',
        'README.md'
    ];

	var pkg = [
		'/src/api/',
		'/src/cns/',
		'/src/common/',
		'/src/config/',
		'/src/decorators/',
		'/src/exception/',
		'/src/middleware/',
		'/src/routes/',
		'/src/utils/'
	];
	file.forEach((item) => {
		gulp.src(item)
			.pipe(gulp.dest('publish'));
	});

	pkg.forEach((item) => {
		gulp.src('./dist' + item + '*.js')
			.pipe(gulp.dest('publish' + item));
	});

	gulp.src('./dist/src/*.js')
		.pipe(gulp.dest('publish/src/'));

});

gulp.task('default', ['tsc', 'publish']);